from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter

# 读取Python脚本内容
with open('./modelzoo/swinunetr_brats/dataloader.py', 'r') as file:
    code = file.read()

# 创建HtmlFormatter实例，设置样式和行号等选项
formatter = HtmlFormatter(full=True, linenos=True, style='colorful')

# 使用highlight函数将代码转换为HTML
html_code = highlight(code, PythonLexer(), formatter)

with open('output.html', 'w') as file:
    file.write(html_code)
    
# 输出HTML代码（这里你可以选择将代码打印到控制台或保存到文件）
print(html_code)